package com.go.where.manager.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import com.go.where.manager.dao.FamilySquareDao;
import com.go.where.manager.page.Pagination;
import com.go.where.manager.page.BaseQuery.OrderType;
import com.go.where.manager.pojo.FamilySquareInfo;
import com.go.where.manager.service.FamilySquareService;

@Service("familySquareService")
public class FamilySquareServiceImpl implements FamilySquareService {

	@Resource(name = "familySquareDao")
	private FamilySquareDao familySquareDao;

	@Override
	public FamilySquareInfo queryByPrimartKey(String cid) {
		return familySquareDao.getByKey(cid);
	}

	@Override
	public Pagination<FamilySquareInfo> queryPage(FamilySquareInfo familyInfo) {
		if (StringUtils.isNotEmpty(familyInfo.getOrderBy())
				&& familyInfo.getOrderType() != null) {
			if (familyInfo.getOrderType() == OrderType.asc) {
				familyInfo.setPage_orderByAsc(familyInfo.getOrderBy());

			} else {
				familyInfo.setPage_orderByDesc(familyInfo.getOrderBy());
			}
		}
		Integer count = familySquareDao.totalCount(familyInfo);
		familyInfo.calculate();
		List<FamilySquareInfo> list = familySquareDao.queryList(familyInfo);
		Pagination<FamilySquareInfo> page = familySquareDao.queryPagination(
				count, list, familyInfo);
		return page;
	}

	@Override
	public int update(FamilySquareInfo videoInfo) {
		return familySquareDao.update(videoInfo);
	}

}
